{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9a8851b3",
   "metadata": {},
   "source": [
    "# zhou二：week09"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f49dbd6",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "> 1. while循环\n",
    "> 2. 购物车项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "d6e12862",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿我是沙，缠缠绵绵到天涯…… 0\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 1\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 2\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 3\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 4\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 5\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 6\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 7\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 8\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 9\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 10\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 11\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 12\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 13\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 14\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 15\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 16\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 17\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 18\n",
      "你是风儿我是沙，缠缠绵绵到天涯…… 19\n"
     ]
    }
   ],
   "source": [
    "#while True 可以实现 for + range 的方法\n",
    "#while True 一般用于不确定的循环次数或者无限次循环操作\n",
    "count = 0\n",
    "while True:\n",
    "    print(\"你是风儿我是沙，缠缠绵绵到天涯……\",count)\n",
    "    count +=1\n",
    "    if count == 20:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "3da72ddb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card:59\n"
     ]
    }
   ],
   "source": [
    "#猜数字小游戏：0<n<100,5次机会猜数字，每次猜完 出题人提示你猜的有点大或有点小\n",
    "\n",
    "hide_card = int(input(\"hide_card:\"))#出题人\n",
    "count = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "51dab29a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "游戏开始了\n",
      "guess_digit:77\n",
      "往小了想想.\n",
      "guess_digit:66\n",
      "往小了想想.\n",
      "guess_digit:44\n",
      "往大了猜.\n",
      "guess_digit:33\n",
      "往大了猜.\n",
      "guess_digit:55\n",
      "往大了猜.\n",
      "猜了这么多次都不对，你个傻瓜！\n",
      "正确答案是：59\n"
     ]
    }
   ],
   "source": [
    "if hide_card < 100 and hide_card > 0 :\n",
    "    print(\"游戏开始了\")\n",
    "    while True:\n",
    "        if count <5:\n",
    "            guess_digit = int(input(\"guess_digit:\"))#玩游戏的人\n",
    "            if guess_digit == hide_card:\n",
    "                print(\"yes,you got it.\")\n",
    "                break\n",
    "            elif guess_digit > hide_card:\n",
    "                print(\"往小了想想.\")\n",
    "            else:\n",
    "                print(\"往大了猜.\")\n",
    "            count = count+1\n",
    "        else:\n",
    "            print(\"猜了这么多次都不对，你个傻瓜！\")\n",
    "            print(\"正确答案是：%s\"%hide_card)\n",
    "            break\n",
    "else:\n",
    "    print(\"请输入0-99之间的数字，不要耍赖！\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46b2026c",
   "metadata": {},
   "source": [
    "## 购物车项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "dedf9cbf",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额:100\n",
      "-----cjh的奶茶店 商品列表-----\n",
      "0 蜜桃乌龙 9 元\n",
      "1 柠檬四季春 8 元\n",
      "2 草莓波波奶盖 10 元\n",
      "3 杨枝甘露 12 元\n",
      "请输入商品编号:1\n",
      "购买成功，请等待制作。您的余额还有:92元\n",
      "-----cjh的奶茶店 商品列表-----\n",
      "0 蜜桃乌龙 9 元\n",
      "1 柠檬四季春 8 元\n",
      "2 草莓波波奶盖 10 元\n",
      "3 杨枝甘露 12 元\n",
      "请输入商品编号:q\n",
      "感谢您的购买，欢迎下次光临~\n",
      "您购买了的商品有： [['柠檬四季春', 8]]\n",
      "您的余额还有:92元\n"
     ]
    }
   ],
   "source": [
    "# 1.运行程序后，让用户输入支付宝余额，然后打印商品列表给用户\n",
    "good_list = [\n",
    "    [\"蜜桃乌龙\",9],\n",
    "    [\"柠檬四季春\",8],\n",
    "    [\"草莓波波奶盖\",10],\n",
    "    [\"杨枝甘露\",12],\n",
    "]\n",
    "#数据存放，列表的增加（append）\n",
    "shopping_list = []\n",
    "AliPay = int(input(\"请输入余额:\"))\n",
    "\n",
    "while True:\n",
    "    print(\"-----cjh的奶茶店 商品列表-----\")\n",
    "    for i in range(4):\n",
    "        print(i,good_list[i][0],good_list[i][1],\"元\")\n",
    "    \n",
    "    # 2.让用户输入商品编号进行商品的购买\n",
    "    user_choice = input(\"请输入商品编号:\")\n",
    "\n",
    "    # 3.用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户\n",
    "    # 3.1 用户输入商品序号（数值）\n",
    "    if user_choice.isdigit() and int(user_choice)<len(good_list) and int(user_choice)>=0:\n",
    "        user_choice = int(user_choice)\n",
    "        if AliPay >= good_list[user_choice][1]:\n",
    "            #余额足够\n",
    "            AliPay = AliPay - good_list[user_choice][1] #更新用户余额\n",
    "            shopping_list.append(good_list[user_choice])\n",
    "            print(\"购买成功，请等待制作。您的余额还有:%s元\" %(AliPay))\n",
    "        else:\n",
    "            #余额不足\n",
    "            print(\"您的余额不足\"+str(good_list[user_choice][1])+\"元，请更换支付方式或选择其他商品~欢迎再来尝试！\")\n",
    "    #3.2 用户输入其他\n",
    "    elif user_choice == \"q\":\n",
    "        print(\"感谢您的购买，欢迎下次光临~\")\n",
    "        print(\"您购买了的商品有：\",shopping_list)\n",
    "        print(\"您的余额还有:%s元\"%(AliPay))\n",
    "        break\n",
    "    else:\n",
    "        print(\"您输入的商品不存在或者您输入的内容有误，请重试！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f9a45b85",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
